<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>E.D.D.I Restful API</title>
    <link rel="stylesheet" href="/text/css/swagger.css" type="text/css"/>
    <link rel="stylesheet" href="/text/css/screen.css" media="screen" type="text/css"/>
    <link rel="stylesheet" href="/text/css/print.css" media="print" type="text/css"/>
    <script type="text/javascript" src="/text/js/swagger.js"></script>
    <style>
        html {
            box-sizing: border-box;
            overflow: -moz-scrollbars-vertical;
            overflow-y: scroll;
        }

        *,
        *:before,
        *:after {
            box-sizing: inherit;
        }

        body {
            margin: 0;
            background: #fafafa;
        }
    </style>
</head>

<body>
<div class="swagger-ui eddi-header">
    <header>
        <div>
            <img src="/binary/img/logo_high.png"/>
            <span>Enhanced Dialog Driven Intelligence / Restful API</span>
        </div>
    </header>
</div>
<div id="message-bar" class="swagger-ui-wrap" data-sw-translate>&nbsp;</div>
<br><br>
<div id="swagger-ui"></div>

<script src="/text/js/swagger-standalone.js"></script>
<script>
    window.onload = function () {
        var url = window.location.search.match(/url=([^&]+)/);
        if (url && url.length > 1) {
            url = decodeURIComponent(url[1]);
        } else {
            var baseUrl = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
            url = baseUrl + "/swagger.json";
        }

        $.getJSON(url, function (spec) {

            console.log(window.location.protocol);
            if (window.location.protocol.slice(0, -1) === 'http') {
                spec.schemes = ['http', 'https'];
            } else {
                spec.schemes = ['https', 'http'];
            }

            console.log(spec);
            // Begin Swagger UI call region
            const ui = SwaggerUIBundle({
                spec: spec,
                dom_id: '#swagger-ui',
                deepLinking: true,
                presets: [
                    SwaggerUIBundle.presets.apis,
                    SwaggerUIStandalonePreset
                ],
                plugins: [
                    SwaggerUIBundle.plugins.DownloadUrl
                ],
                layout: 'BaseLayout',
                supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
                onComplete: function (swaggerApi, swaggerUi) {
                    var initOptions = {
                        responseMode: 'fragment',
                        flow: 'standard'
                    };

                    keycloak.init(initOptions).success(function (authenticated) {
                        console.log('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
                        if (!authenticated) {
                            keycloak.login();
                        }
                    }).error(function () {
                        console.log('Init Error');
                    });

                    initOAuth({
                        clientId: "eddi-engine",
                        realm: "EDDI",
                        appName: "eddi-engine",
                    });

                    if (window.SwaggerTranslator) {
                        window.SwaggerTranslator.translate();
                    }
                },
                onFailure: function (data) {
                    log("Unable to Load SwaggerUI");
                },
                docExpansion: "none",
                jsonEditor: true,
                defaultModelRendering: 'schema',
                showRequestHeaders: true,
                tagsSorter: 'alpha'
            });
            // End Swagger UI call region

            window.ui = ui
        });
    }
</script>
</body>
</html>
